/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.chrfra.backing;

import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.servlet.http.HttpSession;

import javax.faces.context.FacesContext;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.validation.constraints.*;

/**
 *
 * @author David
 */
@ManagedBean
@ApplicationScoped
public class UserSessionBean {

    String loginname;
    String password;
    private String loggedIn = "false";

    public String getLoginname() {
        return loginname;
    }

    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setLoggedIn() {
        //((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false)).setAttribute("true", loggedIn);
        loggedIn ="true";
    }

    public String setLoggedOut() {
        //((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false)).setAttribute("false", loggedIn);
        loggedIn="false";
        return "onLogout";
    }

    public boolean getLoggedIn() {
        return loggedIn.equals("true");
        //return false;
    }

    public String CheckValidUser() {
        // if user login credentials are valid, store user as logged in
        if (loginname.equals("app")
                && password.equals("app")) {
            System.out.println("LOGGED IN SUCESSFULLLY");
            setLoggedIn();
            return "success";
        } else {
            return "fail";
        }
    }
}
